﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Text;
using FineUI;

namespace lcmyjobs.Web.Admin
{
    public partial class newsadd : System.Web.UI.Page
    {
        protected void btnSave_Click(object sender, EventArgs e)
        {

            string ntitle = this.txtntitle.Text;
            //string ncontent = this.txtncontent.Text;
            string ncontent = Request.Form["UEditor1"].ToString();
            int ntid = int.Parse(this.ddlid.SelectedValue.ToString());
            SqlParameter[] parameters = {
					new SqlParameter("@nid", SqlDbType.Int,4),
					new SqlParameter("@ntitle", SqlDbType.NVarChar,50),										
					new SqlParameter("@ncontent", SqlDbType.Text),
					new SqlParameter("@ntid", SqlDbType.Int,4),
                    new SqlParameter("@aid", SqlDbType.Int,4)
                                        };
            if (Request.QueryString["id"] != null)
                parameters[0].Value = Request.QueryString["id"].ToString();
            parameters[1].Value = ntitle;
            parameters[2].Value = ncontent;
            parameters[3].Value = ntid;
            //parameters[4].Value = 2;//管理员的ID编号

            int aid = 0;
            if (Session["admin_id"] != null)
            {
                aid = Convert.ToInt32(Session["admin_id"]);

                parameters[4].Value = aid;//管理员的ID编号
                lcmyjobs.BLL.news bll = new lcmyjobs.BLL.news();
                if (bll.Add(parameters))
                    Maticsoft.Common.MessageBox.Show(this, "保存成功！");
                else
                    Maticsoft.Common.MessageBox.Show(this, "保存失败！");
            }
            else
            {
                Maticsoft.Common.MessageBox.ResponseScript(this, "alert('由于长时间未操作，登陆已过期！请重新登陆。');top.location.href='adminlogin2.aspx'");
            }

          
        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("newslist.aspx");
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Session["AdminLogin2"] != null)
                {
                    bind();
                    if (Request.QueryString["id"] != null)
                    {
                        getnews(int.Parse(Request.QueryString["id"].ToString()));

                    }
                }
                else
                {
                    Maticsoft.Common.MessageBox.ResponseScript(this, "alert('请先登陆！');top.location.href='adminlogin2.aspx'");
                }

            }

        }
        protected void getnews(int id)
        {
            lcmyjobs.BLL.news n = new BLL.news();
            DataSet ds = n.GetNews(id);
            if (ds.Tables[0].Rows.Count > 0)
            {
                //ntitle, ntime,truename,ntname,ncontent,ntid
                ddlid.SelectedValue = ds.Tables[0].Rows[0][5].ToString();
                txtntitle.Text = ds.Tables[0].Rows[0][0].ToString();
                //txtncontent.Text = ds.Tables[0].Rows[0][4].ToString();
                
                string content = ds.Tables[0].Rows[0]["ncontent"].ToString();
                
                //PageContext.RegisterStartupScript(String.Format("updateUEditor({0});", JsHelper.Enquote(content)));
                PageContext.RegisterStartupScript(JsHelper.GetDeferScript(String.Format("updateUEditor({0});", JsHelper.Enquote(content)), 500));
            }

        }
        protected void bind()
        {
            lcmyjobs.BLL.news_type bn = new BLL.news_type();
            DataSet ds = bn.GetList(" ntid<>11 and ntid<>12 and ntid<>13 and ntid<>14 and ntid<>15 ");
            this.ddlid.DataSource = ds.Tables[0];
            this.ddlid.DataTextField = "ntname";
            this.ddlid.DataValueField = "ntid";
            this.ddlid.DataBind();
        }
    }
}